package com.shop2cn.iapi.couponmanage.testcase.old;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.http.client.ClientProtocolException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.coupon.parameter.UserReceiveResultInfo;
import com.shop2cn.iapi.coupon.parameter.UserReceiveResultList;
import com.shop2cn.iapi.couponmanage.parameter.CreateCouponBean;
import com.shop2cn.iapi.couponmanage.parameter.SellerCreateBatchBean;
import com.shop2cn.iapi.couponmanage.parameter.SendSmallCouponBean;
import com.shop2cn.iapi.couponmanage.service.CreateCouponCall;
import com.shop2cn.iapi.couponmanage.service.SellerCreateBatchCall;
import com.shop2cn.iapi.couponmanage.service.SendSmallCouponCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.CouponShop2cnMCallService;
import com.ymttest.database.model.coupon;
import com.ymttest.database.model.couponbatch;
import com.ymttest.database.sqlwapper.couponWapper;
import com.ymttest.database.sqlwapper.couponbatchWapper;
import com.ymttest.utils.MapUtil;
import com.ymttest.utils.TestDataManager;
/**
*商家小批量发放优惠券用例
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SendSmallCoupon{
	private static SendSmallCouponBean sendsmallcouponBean;
	private static SendSmallCouponCall sendsmallcouponCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("商家小批量发放优惠券用例");
	}

	@Before
	public void caseUp() {
		sendsmallcouponBean=new SendSmallCouponBean();
		sendsmallcouponCall=new SendSmallCouponCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(sendsmallcouponCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SendSmallCoupon_001() {
		Logger.start(true,"商家小批量发放优惠券");
		try {
			CouponShop2cnMCallService CouponShop2cnMCallService = new CouponShop2cnMCallService();
			
			sendsmallcouponBean = CouponShop2cnMCallService.setSendSmallCouponBean();
			
			sendsmallcouponCall.setData(sendsmallcouponBean);
			sendsmallcouponCall.callService();			
			
			verifyReturn();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SendSmallCoupon_003() {
		Logger.start(true,"反例-批次编号不能为空");
		try {
			
			CouponShop2cnMCallService CouponShop2cnMCallService = new CouponShop2cnMCallService();
			
			sendsmallcouponBean = CouponShop2cnMCallService.setSendSmallCouponBean();
		
			sendsmallcouponBean.setBatchCode(null);

			sendsmallcouponCall.setData(sendsmallcouponBean);
			sendsmallcouponCall.callService();	
			
			Logger.verifyEquals("1", sendsmallcouponCall.getCode(), "验证返回code");
			Logger.verifyIsContains("batchCode:批次编号不能为空", sendsmallcouponCall.getMessage(), "验证返回Message");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SendSmallCoupon_004() {
		Logger.start(true,"反例-请传入要发放给哪些用户-null");
		try {
			

			CouponShop2cnMCallService CouponShop2cnMCallService = new CouponShop2cnMCallService();
			
			sendsmallcouponBean = CouponShop2cnMCallService.setSendSmallCouponBean();
			
			sendsmallcouponBean.setUserIds(null);

			sendsmallcouponCall.setData(sendsmallcouponBean);
			sendsmallcouponCall.callService();	
			
			Logger.verifyEquals("1", sendsmallcouponCall.getCode(), "验证返回code");
			Logger.verifyIsContains("userIds:请传入要发放给哪些用户", sendsmallcouponCall.getMessage(), "验证返回Message");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SendSmallCoupon_005() {
		Logger.start(true,"反例-请传入要发放给哪些用户-空list");
		try {

			CouponShop2cnMCallService CouponShop2cnMCallService = new CouponShop2cnMCallService();
			
			sendsmallcouponBean = CouponShop2cnMCallService.setSendSmallCouponBean();
			
			sendsmallcouponBean.setUserIds(new ArrayList<>());

			sendsmallcouponCall.setData(sendsmallcouponBean);
			sendsmallcouponCall.callService();	
			
			Logger.verifyEquals("1", sendsmallcouponCall.getCode(), "验证返回code");
			Logger.verifyIsContains("userIds:请传入要发放给哪些用户并且最多不超过20个用户", sendsmallcouponCall.getMessage(), "验证返回Message");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SendSmallCoupon_006() {
		Logger.start(true,"反例-请提供商家ID");
		try {

			CouponShop2cnMCallService CouponShop2cnMCallService = new CouponShop2cnMCallService();
			
			sendsmallcouponBean = CouponShop2cnMCallService.setSendSmallCouponBean();
			
			sendsmallcouponBean.setSellerId(null);

			sendsmallcouponCall.setData(sendsmallcouponBean);
			sendsmallcouponCall.callService();	
			
//			Logger.verifyEquals("2", sendsmallcouponCall.getCode(), "验证返回code");
//			Logger.verifyIsContains("平台不允许发放商家券", sendsmallcouponCall.getMessage(), "验证返回Message");
			UserReceiveResultList userReceiveResultList=sendsmallcouponCall.getUserReceiveResultList();
			for(int i=0;i<userReceiveResultList.getUserReceiveResultList().size();i++)
			{
				UserReceiveResultInfo userReceiveResultInfo=userReceiveResultList.getUserReceiveResultList().get(i);
				Logger.verifyEquals(24, userReceiveResultInfo.getReceiveFailReason(), "验证返回ReceiveFailReason");
				Logger.verifyEquals(true, userReceiveResultInfo.getRemark().contains("不属于平台批次"), "验证返回的Remark");
				Logger.verifyEquals(false, userReceiveResultInfo.getIsReceiveSuccess(), "验证返回的isReceiveSuccess");
			}
			// 验证数据库
			couponbatch batch = new couponbatchWapper().selectBybatchCode(sendsmallcouponBean.getBatchCode()).get(0);
			List<coupon> coupons  =  new couponWapper().selectByBatchId(batch.getBatchId());
			
			Logger.verifyEquals(0, coupons.size(), "验证数据库生成Coupon条数正确");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SendSmallCoupon_007() {
		Logger.start(true,"反例-超过20个用户");
		try {

			CouponShop2cnMCallService CouponShop2cnMCallService = new CouponShop2cnMCallService();
			
			sendsmallcouponBean = CouponShop2cnMCallService.setSendSmallCouponBean();
			
			List<Integer> userIds = new ArrayList<>();
			
			for(int i=0;i<21;i++)
			{
				userIds.add(TestDataManager.getRandomIntNum(8));
			}

			sendsmallcouponBean.setUserIds(userIds);

			sendsmallcouponCall.setData(sendsmallcouponBean);
			sendsmallcouponCall.callService();	
			Logger.verifyEquals("1", sendsmallcouponCall.getCode(), "验证返回code");
			Logger.verifyIsContains("userIds:请传入要发放给哪些用户并且最多不超过20个用户", sendsmallcouponCall.getMessage(), "验证返回Message");
			// 验证数据库
			couponbatch batch = new couponbatchWapper().selectBybatchCode(sendsmallcouponBean.getBatchCode()).get(0);
			List<coupon> coupons  =  new couponWapper().selectByBatchId(batch.getBatchId());
			
			Logger.verifyEquals(0, coupons.size(), "验证数据库生成Coupon条数正确");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SendSmallCoupon_008() {
		Logger.start(true,"反例-批次不存在");
		try {

			CouponShop2cnMCallService CouponShop2cnMCallService = new CouponShop2cnMCallService();			
			sendsmallcouponBean = CouponShop2cnMCallService.setSendSmallCouponBean();
			
			sendsmallcouponBean.setBatchCode("99999999");

			sendsmallcouponCall.setData(sendsmallcouponBean);
			sendsmallcouponCall.callService();	
			
//			Logger.verifyEquals("2", sendsmallcouponCall.getCode(), "验证返回code");
//			Logger.verifyIsContains("批次不存在", sendsmallcouponCall.getMessage(), "验证返回Message");
			UserReceiveResultList userReceiveResultList=sendsmallcouponCall.getUserReceiveResultList();
			for(int i=0;i<userReceiveResultList.getUserReceiveResultList().size();i++)
			{
				UserReceiveResultInfo userReceiveResultInfo=userReceiveResultList.getUserReceiveResultList().get(i);
				Logger.verifyEquals(8, userReceiveResultInfo.getReceiveFailReason(), "验证返回ReceiveFailReason");
				Logger.verifyEquals(true, userReceiveResultInfo.getRemark().contains("批次不存在"), "验证返回的Remark");
				Logger.verifyEquals(false, userReceiveResultInfo.getIsReceiveSuccess(), "验证返回的isReceiveSuccess");
			}
			// 验证数据库
			List<couponbatch> batch = new couponbatchWapper().selectBybatchCode(sendsmallcouponBean.getBatchCode());
//			if(batch.size()>0)
//			List<coupon> coupons  =  new couponWapper().selectByBatchId(batch.get(0).getBatchId());
			Logger.verifyEquals(0, batch.size(), "验证数据库生成Coupon条数正确");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SendSmallCoupon_009() {
		Logger.start(true,"反例-商家创建发放任务，但批次不属于当前商家创建");
		try {

			CouponShop2cnMCallService CouponShop2cnMCallService = new CouponShop2cnMCallService();			
			sendsmallcouponBean = CouponShop2cnMCallService.setSendSmallCouponBean();
			
			sendsmallcouponBean.setSellerId(1111);

			sendsmallcouponCall.setData(sendsmallcouponBean);
			sendsmallcouponCall.callService();	
			
//			Logger.verifyEquals("2", sendsmallcouponCall.getCode(), "验证返回code");
//			Logger.verifyIsContains("商家发放优惠券，发放的批次不属于此商家", sendsmallcouponCall.getMessage(), "验证返回Message");
			UserReceiveResultList userReceiveResultList=sendsmallcouponCall.getUserReceiveResultList();
			for(int i=0;i<userReceiveResultList.getUserReceiveResultList().size();i++)
			{
				UserReceiveResultInfo userReceiveResultInfo=userReceiveResultList.getUserReceiveResultList().get(i);
				Logger.verifyEquals(25, userReceiveResultInfo.getReceiveFailReason(), "验证返回ReceiveFailReason");
				Logger.verifyEquals(true, userReceiveResultInfo.getRemark().contains("优惠券批次不属于当前买手"), "验证返回的Remark");
				Logger.verifyEquals(false, userReceiveResultInfo.getIsReceiveSuccess(), "验证返回的isReceiveSuccess");
			}
			// 验证数据库
			couponbatch batch = new couponbatchWapper().selectBybatchCode(sendsmallcouponBean.getBatchCode()).get(0);
			List<coupon> coupons  =  new couponWapper().selectByBatchId(batch.getBatchId());
			
			Logger.verifyEquals(0, coupons.size(), "验证数据库生成Coupon条数正确");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SendSmallCoupon_010() {
		Logger.start(true,"反例-创建发放任务，商家不允许发放平台券");
		try {
			CouponShop2cnMCallService CouponShop2cnMCallService = new CouponShop2cnMCallService();
			
			 CreateCouponBean createCouponBean = CouponShop2cnMCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			 CreateCouponCall createCouponCall = CouponShop2cnMCallService.createPlatformCoupon(createCouponBean);
						
				List<Integer> userIds = new ArrayList<>();
				
				userIds.add(TestDataManager.getRandomIntNum(8));
				userIds.add(TestDataManager.getRandomIntNum(8));
				userIds.add(TestDataManager.getRandomIntNum(8));

			sendsmallcouponBean = CouponShop2cnMCallService.setSendsmallcouponBean(userIds, createCouponCall.getBatchCode(), 3383, "dddd");;

			sendsmallcouponCall.setData(sendsmallcouponBean);
			sendsmallcouponCall.callService();	
			
//			Logger.verifyEquals("2", sendsmallcouponCall.getCode(), "验证返回code");
//			Logger.verifyIsContains("商家不允许发放平台券", sendsmallcouponCall.getMessage(), "验证返回Message");
			
			UserReceiveResultList userReceiveResultList=sendsmallcouponCall.getUserReceiveResultList();
			for(int i=0;i<userReceiveResultList.getUserReceiveResultList().size();i++)
			{
				UserReceiveResultInfo userReceiveResultInfo=userReceiveResultList.getUserReceiveResultList().get(i);
				Logger.verifyEquals(25, userReceiveResultInfo.getReceiveFailReason(), "验证返回ReceiveFailReason");
				Logger.verifyEquals(true, userReceiveResultInfo.getRemark().contains("优惠券批次不属于当前买手"), "验证返回的Remark");
				Logger.verifyEquals(false, userReceiveResultInfo.getIsReceiveSuccess(), "验证返回的isReceiveSuccess");
			}
			// 验证数据库
			couponbatch batch = new couponbatchWapper().selectBybatchCode(sendsmallcouponBean.getBatchCode()).get(0);
			List<coupon> coupons  =  new couponWapper().selectByBatchId(batch.getBatchId());
			
			Logger.verifyEquals(0, coupons.size(), "验证数据库生成Coupon条数正确");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SendSmallCoupon_011() {
		Logger.start(false,"反例-批次已作废");
		try {
			CouponShop2cnMCallService CouponShop2cnMCallService = new CouponShop2cnMCallService();			
			sendsmallcouponBean = CouponShop2cnMCallService.setSendSmallCouponBean();
		
			CouponShop2cnMCallService.InvalidSellerBatch(sendsmallcouponBean.getSellerId(),sendsmallcouponBean.getBatchCode());

			sendsmallcouponCall.setData(sendsmallcouponBean);
			sendsmallcouponCall.callService();	
			
			Logger.verifyEquals("0", sendsmallcouponCall.getCode(), "验证返回code");

			Logger.verifyEquals("操作成功！", sendsmallcouponCall.getMessage(), "验证返回Message");

			UserReceiveResultList userReceiveResultList = sendsmallcouponCall.getUserReceiveResultList();
			
			List<UserReceiveResultInfo> list = userReceiveResultList.getUserReceiveResultList();
			
			List<Integer> users=sendsmallcouponBean.getUserIds();
			List<Integer> userids=new ArrayList<>();
			
			// 验证返回
			for(int i=0;i<list.size();i++)
			{
				UserReceiveResultInfo item = list.get(i);

				userids.add(item.getUserId());
				
				Logger.verifyEquals(sendsmallcouponBean.getBatchCode(), item.getBatchCode(), "验证返回BatchCode");
				Logger.verifyEquals(false, item.getIsReceiveSuccess(), "验证返回IsReceiveSuccess");
				Logger.verifyEquals(4, item.getReceiveFailReason(), "验证返回ReceiveFailReason");
				Logger.verifyEquals(true, item.getRemark().contains("批次已作废"), "验证返回的Remark");
			}
			Logger.verifyEquals(true,TestDataManager.isListEqual(userids, users), "验证返回UserId");
		
			// 验证数据库
			couponbatch batch = new couponbatchWapper().selectBybatchCode(sendsmallcouponBean.getBatchCode()).get(0);
			List<coupon> coupons  =  new couponWapper().selectByBatchId(batch.getBatchId());
			
			Logger.verifyEquals(0, coupons.size(), "验证数据库生成Coupon条数正确");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SendSmallCoupon_012() {
		Logger.start(true,"反例-批次已过期");
		try {
			CouponShop2cnMCallService CouponShop2cnMCallService = new CouponShop2cnMCallService();			
			sendsmallcouponBean = CouponShop2cnMCallService.setSendSmallCouponBean();
		
			 // 设置优惠券过期
          //  Date date = new Date(new Date().getTime() - 24 * 60 * 60 * 1000);
            
			Date dNow = new Date(); // 当前时间
	        Date dBefore = new Date();
	        Date dAfter = new Date();

	        Calendar calendar1 = Calendar.getInstance(); // 得到日历
	        calendar1.setTime(dNow);// 把当前时间赋给日历
	        calendar1.add(Calendar.DAY_OF_MONTH, -10); // 设置为前10天
	        dBefore = calendar1.getTime(); // 得到前10天的时间

	        Calendar calendar2 = Calendar.getInstance(); // 得到日历
	        calendar2.setTime(dNow);// 把当前时间赋给日历
	        calendar2.add(Calendar.DAY_OF_MONTH, -1); // 设置为前1天
	        dAfter = calendar2.getTime(); // 得到前一天的时间
	        
            int batchId =
                    new couponbatchWapper().selectBybatchCode(sendsmallcouponBean.getBatchCode()).get(0).getBatchId();
            new couponbatchWapper().setValidStart(batchId,dBefore);
            new couponbatchWapper().setValidEnd(batchId, dAfter);
            
			sendsmallcouponCall.setData(sendsmallcouponBean);
			sendsmallcouponCall.callService();	
			
			Logger.verifyEquals("0", sendsmallcouponCall.getCode(), "验证返回code");

			Logger.verifyEquals("操作成功！", sendsmallcouponCall.getMessage(), "验证返回Message");

			UserReceiveResultList userReceiveResultList = sendsmallcouponCall.getUserReceiveResultList();
			
			List<UserReceiveResultInfo> list = userReceiveResultList.getUserReceiveResultList();
			
			List<Integer> users=sendsmallcouponBean.getUserIds();

			List<Integer> userids=new ArrayList<>();
			
			// 验证返回
			for(int i=0;i<list.size();i++)
			{
				UserReceiveResultInfo item = list.get(i);

				userids.add(item.getUserId());
				Logger.verifyEquals(sendsmallcouponBean.getBatchCode(), item.getBatchCode(), "验证返回BatchCode");
				Logger.verifyEquals(false, item.getIsReceiveSuccess(), "验证返回IsReceiveSuccess");
				Logger.verifyEquals(3, item.getReceiveFailReason(), "验证返回ReceiveFailReason");
				Logger.verifyEquals(true, item.getRemark().contains("批次已过期"), "验证返回的Remark");
			}
			
			Logger.verifyEquals(true,TestDataManager.isListEqual(userids, users), "验证返回UserId");
			
			// 验证数据库
			couponbatch batch = new couponbatchWapper().selectBybatchCode(sendsmallcouponBean.getBatchCode()).get(0);
			List<coupon> coupons  =  new couponWapper().selectByBatchId(batch.getBatchId());
			
			Logger.verifyEquals(0, coupons.size(), "验证数据库生成Coupon条数正确");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SendSmallCoupon_013() {
		Logger.start(true,"反例-批次已领完");
		try {
			CouponShop2cnMCallService CouponShop2cnMCallService = new CouponShop2cnMCallService();			
			sendsmallcouponBean = CouponShop2cnMCallService.setSendSmallCouponBean();
		
			  couponbatch batch = new couponbatchWapper().selectBybatchCode(sendsmallcouponBean.getBatchCode()).get(0);
			  int batchId =
	                    new couponbatchWapper().selectBybatchCode(sendsmallcouponBean.getBatchCode()).get(0).getBatchId();
	            new couponbatchWapper().setiReceiveCount(batchId, batch.getTotalNum());
	            

			sendsmallcouponCall.setData(sendsmallcouponBean);
			sendsmallcouponCall.callService();	
			
			Logger.verifyEquals("0", sendsmallcouponCall.getCode(), "验证返回code");

			Logger.verifyEquals("操作成功！", sendsmallcouponCall.getMessage(), "验证返回Message");

			UserReceiveResultList userReceiveResultList = sendsmallcouponCall.getUserReceiveResultList();
			
			List<UserReceiveResultInfo> list = userReceiveResultList.getUserReceiveResultList();
			
			List<Integer> users=sendsmallcouponBean.getUserIds();
			
			// 验证返回
			for(int i=0;i<list.size();i++)
			{
				UserReceiveResultInfo item = list.get(i);
				Logger.verifyEquals(sendsmallcouponBean.getBatchCode(), item.getBatchCode(), "验证返回BatchCode");
				Logger.verifyEquals(false, item.getIsReceiveSuccess(), "验证返回IsReceiveSuccess");
				Logger.verifyEquals(1, item.getReceiveFailReason(), "验证返回ReceiveFailReason");
			}
			
			// 验证数据库
			couponbatch batch1 = new couponbatchWapper().selectBybatchCode(sendsmallcouponBean.getBatchCode()).get(0);
			List<coupon> coupons  =  new couponWapper().selectByBatchId(batch1.getBatchId());
			
			Logger.verifyEquals(0, coupons.size(), "验证数据库生成Coupon条数正确");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SendSmallCoupon_014() {
		Logger.start(true,"商家小批量发放优惠券-批次过期,返回查不到数据-JIRACONN-23166");
		try {
			CouponShop2cnMCallService CouponShop2cnMCallService = new CouponShop2cnMCallService();
			
			sendsmallcouponBean = CouponShop2cnMCallService.setSendSmallCouponBean();
			
			
			Date dstart = new Date(); // 当前时间
	        Date dend = new Date();

	        Calendar calendar = Calendar.getInstance(); // 得到日历
	        calendar.setTime(dstart);// 把当前时间赋给日历
	        calendar.add(Calendar.DAY_OF_MONTH, -2); // 设置为前一天
	        dstart = calendar.getTime(); // 得到前一天的时间
	        
	        Calendar calendar2 = Calendar.getInstance(); // 得到日历
	        calendar2.setTime(dend);// 把当前时间赋给日历
	        calendar2.add(Calendar.DAY_OF_MONTH, -1); // 设置为前一天
	        dend = calendar2.getTime(); // 得到前一天的时间
			 new couponbatchWapper().setAcquireStartTime(sendsmallcouponBean.getBatchCode(), dstart);
			 new couponbatchWapper().setAcquireEndTime(sendsmallcouponBean.getBatchCode(), dend);
			
			sendsmallcouponCall.setData(sendsmallcouponBean);
			sendsmallcouponCall.callService();			

			verifyReturn();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SendSmallCoupon_015() {
		Logger.start(true,"商家小批量发放优惠券-批次过期,返回查不到数据-分销");
		try {
			Logger.start(true,"商家小批量发放优惠券");
			try {
				CouponShop2cnMCallService CouponShop2cnMCallService = new CouponShop2cnMCallService();
				
				sendsmallcouponBean = CouponShop2cnMCallService.setSendSmallCouponBean();
		        //分销
				couponbatchWapper couponbatchWapper=new couponbatchWapper();
				couponbatchWapper.setPlatformSource(1, sendsmallcouponBean.getBatchCode());

				sendsmallcouponCall.setData(sendsmallcouponBean);
				sendsmallcouponCall.callService();			
				
				verifyReturn();
				
			} catch (Exception e) {
				Logger.fail(e);
			}
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SendSmallCoupon_016() {
		Logger.start(true,"商家小批量发放优惠券-验证仅直播时优惠券,有效时间为发放开始计算12小时 后结束");
		try {
			sendsmallcouponBean = setSendSmallCouponBean2();
			
			sendsmallcouponCall.setData(sendsmallcouponBean);
			sendsmallcouponCall.callService();			
			
			verifyReturn();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	public SendSmallCouponBean setSendSmallCouponBean2()
			throws ClientProtocolException, IOException {
		Logger.comment("创建商家券默认的SendSmallCouponBean");
		SendSmallCouponBean sendSmallCouponBean = new SendSmallCouponBean();

		List<Integer> userIds = new ArrayList<>();

		userIds.add(TestDataManager.getRandomIntNum(8));
		userIds.add(TestDataManager.getRandomIntNum(8));
		userIds.add(TestDataManager.getRandomIntNum(8));

		// 创建优惠券批次
		CouponShop2cnMCallService CouponShop2cnMCallService = new CouponShop2cnMCallService();
		SellerCreateBatchBean sellercreatebatchBean = CouponShop2cnMCallService
				.setDefaultSellerCreateBatchBean();
		sellercreatebatchBean.setCouponType((byte)4);//仅限直播
		
		SellerCreateBatchCall sellerCreateBatchCall = CouponShop2cnMCallService
				.SellerCreateBatch(sellercreatebatchBean);
		
		return CouponShop2cnMCallService.setSendsmallcouponBean(userIds,
				sellerCreateBatchCall.getBatchCode(),
				sellercreatebatchBean.getSellerId(), "商家店铺名称sss");
	}
	private void verifyReturn()
	{
		Logger.verifyEquals("0", sendsmallcouponCall.getCode(), "验证返回code");

		Logger.verifyEquals("操作成功！", sendsmallcouponCall.getMessage(), "验证返回Message");

		UserReceiveResultList userReceiveResultList = sendsmallcouponCall.getUserReceiveResultList();
		
		List<UserReceiveResultInfo> list = userReceiveResultList.getUserReceiveResultList();
		
		List<Integer> users=sendsmallcouponBean.getUserIds();
		
		List<Integer> userids = new ArrayList<>();
		
		  List<Map> DBresult=new couponbatchWapper().pagingGetSellerValidBatches(
	        		MapUtil.hashMap("sellerId",sendsmallcouponBean.getSellerId(),
					"batchCode",sendsmallcouponBean.getBatchCode()
			));
	      int count=new couponbatchWapper().SendSmallCouponCount(
	        		MapUtil.hashMap("sellerId",sendsmallcouponBean.getSellerId(),
					"batchCode",sendsmallcouponBean.getBatchCode()
			));
	        Logger.verifyEquals((long)count, userReceiveResultList.getUserReceiveResultList()
	        		.stream().filter(u->u.getIsReceiveSuccess()==true).count(),
	                "验证返回的数据与数据库是否一致");
		// 验证返回
		for(int i=0;i<list.size();i++)
		{
			UserReceiveResultInfo item = list.get(i);
			Logger.verifyEquals(sendsmallcouponBean.getBatchCode(), item.getBatchCode(), "验证返回BatchCode");
			Logger.verifyEquals(list.get(i).getIsReceiveSuccess(), item.getIsReceiveSuccess(), "验证返回IsReceiveSuccess");
			Logger.verifyEquals(list.get(i).getReceiveFailReason(), item.getReceiveFailReason(), "验证返回ReceiveFailReason");
			userids.add(item.getUserId());
		}
		
		Logger.verifyEquals(true,TestDataManager.isListEqual(userids, users), "验证返回UserId");
		
		// 验证数据库
		couponbatch batch = new couponbatchWapper().selectBybatchCode(sendsmallcouponBean.getBatchCode()).get(0);
		List<coupon> coupons  =  new couponWapper().selectByBatchId(batch.getBatchId());
		
		Logger.verifyEquals(userReceiveResultList.getUserReceiveResultList()
        		.stream().filter(u->u.getIsReceiveSuccess()==true).count(),(long) coupons.size(), "验证数据库生成Coupon条数正确");
		
		for(int i=0;i<coupons.size();i++)
		{
			coupon coupon = coupons.get(i);
			
        	Logger.verifyEquals(DBresult.get(0).get("BatchCode").toString(),
        			batch.getBatchCode(),
                     "验证返回记录中的BatchCode为传入BatchCode");
        	
			// iCouponSetting
			Logger.verifyEquals(batch.getBatchId(), coupon.getBatchId(),
					"验证数据库表Ymt_Coupon表中iCouponSetting");
			// 优惠券类型 2：链接
			Logger.verifyEquals(2, batch.getSendType(), "验证数据库表Ymt_Coupon表中iCouponType");
			
			
			Logger.verifyEquals(batch.getPlatformSource(), coupon.getPlatformSource(),
					"验证数据库表couponbatch表中字段PlatformSource与coupon表中字段PlatformSource是否一致");
			
			 if(batch.getCouponType()==4)
	         {
	        	 //有效时间为发放开始计算12小时 后结束
	 			Logger.verifyEquals(true,coupon.getAddTime().compareTo(coupon.getValidStart())<=0 ,
						"验证couponCode="+coupon.getCouponCode()+" 数据库表couponbatch表中字段PlatformSource与coupon表中字段ValidStart=AddTime是否一致");
	 			Logger.verifyEquals(true,(long)(coupon.getAddTime().getTime()+12*60*60*1000)<=coupon.getValidEnd().getTime(),
						"验证couponCode="+coupon.getCouponCode()+" 数据库表couponbatch表中字段PlatformSource与coupon表中字段ValidEnd=AddTime往后移12小时");
	         }
		}
        
	}
}